#include "vectors.h"

IDL_MEMINT_VECTOR *IDL_MEMINT_VECTOR_New(IDL_MEMINT n, int initialize)
{

  IDL_MEMINT_VECTOR *v;

  v = calloc(1, sizeof(IDL_MEMINT_VECTOR));
  
  v->n = n;
  v->d = calloc( n, sizeof(IDL_MEMINT) );

  if (initialize)
    {
      IDL_MEMINT i;
      for (i=0;i<n;i++)
	v->d[i] = 0;
    }
  return(v);
}
IDL_MEMINT_VECTOR *IDL_MEMINT_VECTOR_NewFromArray(IDL_MEMINT n, IDL_MEMINT *data)
{

  IDL_MEMINT_VECTOR *v;
  IDL_MEMINT i;
  v = calloc(1, sizeof(IDL_MEMINT_VECTOR));
  
  v->n = n;
  v->d = calloc( n, sizeof(IDL_MEMINT) );

  for (i=0;i<n;i++)
    v->d[i] = data[i];

  return(v);
}

int IDL_MEMINT_Compare(void *i1, void *i2)
{
  return ( *(IDL_MEMINT *)i1 - *(IDL_MEMINT *)i2 );
}


void IDL_MEMINT_VECTOR_Sort(IDL_MEMINT_VECTOR *v)
{
  
  if (v != NULL)
    if (v->d != NULL)
	qsort(v->d, v->n, sizeof(IDL_MEMINT), (void *) IDL_MEMINT_Compare);	

}


void IDL_MEMINT_VECTOR_Free(IDL_MEMINT_VECTOR *v)
{
  if (v)
    {
      if (v->d)
	free(v->d);
      free(v);
    }
}
